/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package converter;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import model.dao.QuanDAO;
import model.entity.Quan;
import model.service.QuanDAOService;

/**
 *
 * @author duy
 */
@ManagedBean
@RequestScoped
@FacesConverter("QuanConverter")
public class QuanIDConverter implements Converter {

    private final QuanDAOService QUAN_SERVICE = QuanDAO.getInstance();

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) {

        Quan quan = null;
        if (value != null) {
            quan = QUAN_SERVICE.getQuanbyMa(Integer.valueOf(value));
        }
        return quan;

    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object value) {
        Quan quan = (Quan) value;
        return quan.getMaquan()+ "";
    }

}
